//
//  DSTabBarController.m
//  weibo
//
//  Created by wudongyang on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DSTabBarController.h"
#import "CenterViewController.h"
#import "DiscoverViewController.h"
#import "MyViewController.h"
#import "HomePageViewController.h"
#import "InformationViewController.h"
#import "DSTabBar.h"
#import "DSNavigationController.h"
@interface DSTabBarController ()

@end

@implementation DSTabBarController
- (void)dealloc
{
    [super dealloc];
    
}
+(void)initialize{
    // 未选中状态下文字大小和颜色(未选中:uncheck)
    NSMutableDictionary *uncheck = [NSMutableDictionary dictionary];
    uncheck[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    uncheck[NSForegroundColorAttributeName] = [UIColor grayColor];
    // 选中状态下文字大小和颜色(选中:selected)
    NSMutableDictionary *selected = [NSMutableDictionary dictionary];
    selected[NSFontAttributeName] = uncheck[NSFontAttributeName];
    selected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象统一设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:uncheck forState:UIControlStateNormal];
    [item setTitleTextAttributes:selected forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加子控制器一(首页)
    [self setupChildVc:[HomePageViewController new] title:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];
    
    // 添加子控制器二(消息)
    [self setupChildVc:[InformationViewController new] title:@"消息" image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];
    
    // 添加子控制器三(发现)
    [self setupChildVc:[DiscoverViewController new] title:@"通讯录" image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];
    
    // 添加子控制器四(我)
    [self setupChildVc:[MyViewController new] title:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
    
    // 更换tabBar
    DSTabBar *mytabBar = [[DSTabBar alloc]init];
    [self setValue:mytabBar forKey:@"TabBar"];
//    self.tabBar
    
    mytabBar.myBlock = ^(void){
        CenterViewController *CenterVC = [[CenterViewController alloc] init];
    [self presentViewController:CenterVC animated:YES completion:^{
        
        
    }];
        [CenterVC release];
    
    };
    [mytabBar release];
    
    
    
    
}
// 初始化子控制器(参数1:Controller 参数2:文字 参数3:未选中图片 参数4:被选中图片)
-(void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:1];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:1];
//    vc.tabBarItem.badgeValue = @"111";
    
    // 包装一个导航控制器,添加导航控制器为tabBarController的子控制器
    DSNavigationController *naVC = [[DSNavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:naVC];
    [naVC release];
    
    
    
}

@end
